/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ejemplo.DAO;

import com.ejemplo.TO.SedeTO;
import com.ejemplo.TO.TerceroTO;
import com.ejemplo.TO.UsuarioTO;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;

/**
 *
 * @author carlosdavid
 */
@Repository
public class UsuarioDAO extends HibernateDaoSupport implements UsuarioDAOInterface  {

    
    @Autowired
    public UsuarioDAO(SessionFactory sessionFactory){
        super.setSessionFactory(sessionFactory);
    }
    @Override
    public List<SedeTO> listarSedes() {
        Session session=getHibernateTemplate().getSessionFactory().openSession();
        
        Query consulta=session.createSQLQuery("select codsede as codsede,sede as sede from sede").
                setResultTransformer(Transformers.aliasToBean(SedeTO.class));
        
    return consulta.list();
    }

    @Override
    public List<UsuarioTO> ObtenerUsuario(String usuario, Integer codsede) {
        Session session=getHibernateTemplate().getSessionFactory().openSession();
        
        Query consulta=session.createSQLQuery("select password as password from usuario where usuario='" + usuario + "' and codsede="+codsede).
                setResultTransformer(Transformers.aliasToBean(UsuarioTO.class));
        
    return consulta.list();
    }



}
